package com.hmdp.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String VOUCHER_EXCHANGE = "voucher.exchange";
    public static final String VOUCHER_QUEUE = "voucher.queue";
    public static final String VOUCHER_ROUTING_KEY = "voucher.created";

    @Bean
    public Exchange voucherExchange() {
        return ExchangeBuilder.directExchange(VOUCHER_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue voucherQueue() {
        return QueueBuilder.durable(VOUCHER_QUEUE).build();
    }

    @Bean
    public Binding voucherBinding() {
        return BindingBuilder.bind(voucherQueue()).to(voucherExchange()).with(VOUCHER_ROUTING_KEY).noargs();
    }
    
    // 添加用于性能测试的队列和交换机
    public static final String PERF_TEST_EXCHANGE = "perf.test.exchange";
    public static final String PERF_TEST_QUEUE = "perf.test.queue";
    public static final String PERF_TEST_ROUTING_KEY = "perf.test.key";
    
    @Bean
    public Exchange perfTestExchange() {
        return ExchangeBuilder.directExchange(PERF_TEST_EXCHANGE).durable(true).build();
    }
    
    @Bean
    public Queue perfTestQueue() {
        return QueueBuilder.durable(PERF_TEST_QUEUE).build();
    }
    
    @Bean
    public Binding perfTestBinding() {
        return BindingBuilder.bind(perfTestQueue()).to(perfTestExchange()).with(PERF_TEST_ROUTING_KEY).noargs();
    }
}